#CONTROL(RelationTree,'Relation Tree Viewing List Box'),PRIMARY('Relation Tree Viewing List Box',OPTKEY),DESCRIPTION('View Relations of ' & %Primary),MULTI,WINDOW,HLP('~TPLControlRelationTree')
#BUTTON('Conditional Color Assignments'),MULTI(%SecondaryConditionalColors,%SecondaryColorCondition),INLINE,HLP('~TPLControlRelationTree_ConditionalColorAssignments')
#BUTTON('Conditional Color Assignments'),MULTI(%PrimaryConditionalColors,%PrimaryColorCondition),INLINE,AT(,,,90),HLP('~TPLControlRelationTree_ConditionalColorAssignments')
#EMBED(%BeforeSecondaryDisplay,'Before Setting Display on Secondary File'),%ActiveTemplateInstance,%Secondary,MAP(%ActiveTemplateInstance,%ActiveTemplateinstanceDescription),MAP(%Secondary,' on ' & %Secondary)
#EMBED(%BeforeAddingSecondaryToQueue,'Before Adding Secondary Record to Queue'),%ActiveTemplateInstance,%Secondary,MAP(%ActiveTemplateInstance,%ActiveTemplateinstanceDescription),MAP(%Secondary,' on ' & %Secondary)
#EMBED(%BeginAddEntryRoutine,'Beginning of Add Record Routine'),%ActiveTemplateInstance,MAP(%ActiveTemplateInstance,%ActiveTemplateinstanceDescription)
#EMBED(%BeforePreparingRecordOnAdd,'Before Preparing Record for Add'),%ActiveTemplateInstance,%Primary,MAP(%ActiveTemplateInstance,%ActiveTemplateinstanceDescription)
#FIX(%File,%Primary)
GET(%File,0)
#FOR(%Field),WHERE(%FieldType = 'MEMO')
CLEAR(%Field)
#ENDFOR
CLEAR(%FilePrefix:Record)
GlobalRequest = InsertRecord
#EMBED(%BeforeCallingUpdateOnAdd,'Before Update Procedure on Add'),%ActiveTemplateInstance,%Primary,MAP(%ActiveTemplateInstance,%ActiveTemplateinstanceDescription)
%PrimaryUpdate
IF GlobalResponse = RequestCompleted
%InstancePrefix:NewItemLevel = 1
%InstancePrefix:NewItemPosition = POSITION(%File)
DO %InstancePrefix:RefreshTree
END
#EMBED(%AfterCallingUpdateOnAdd,'After Update Procedure on Add'),%ActiveTemplateInstance,%Primary,MAP(%ActiveTemplateInstance,%ActiveTemplateinstanceDescription)
#?IF ABS(%InstancePrefix:Level) = %ValueConstruct THEN CYCLE.
#?BREAK
#?END
#?END
#ENDIF
#?REGET(%TreeParentFile,%InstancePrefix:Position)
#EMBED(%BeforePreparingRecordOnAdd,'Before Preparing Record for Add'),%ActiveTemplateInstance,%Primary,MAP(%ActiveTemplateInstance,%ActiveTemplateinstanceDescription)
#?GET(%TreeLevelFile,0)
#FIX(%File,%TreeLevelFile)
#?CLEAR(%FilePrefix:Record)
#FOR(%Field),WHERE(%FieldType = 'MEMO')
#?CLEAR(%Field)
#ENDFOR
#FIX(%Relation,%TreeParentFile)
#FOR(%FileKeyField),WHERE(%FileKeyField AND %FileKeyFieldLink)
#?%FileKeyField = %FileKeyFieldLink
#ENDFOR
#?GlobalRequest = InsertRecord
#FIX(%File,%Primary)
#FIX(%Secondary,%TreeLevelFile)
#EMBED(%BeforeCallingUpdateOnAdd,'Before Update Procedure on Add'),%ActiveTemplateInstance,%Secondary,MAP(%ActiveTemplateInstance,%ActiveTemplateinstanceDescription)
#EMBED(%AfterCallingUpdateOnAdd,'After Update Procedure on Add'),%ActiveTemplateInstance,%Secondary,MAP(%ActiveTemplateInstance,%ActiveTemplateinstanceDescription)
#EMBED(%BeforeCallingUpdateOnEdit,'Before Update Procedure on Edit'),%ActiveTemplateInstance,%Primary,MAP(%ActiveTemplateInstance,%ActiveTemplateinstanceDescription)
%PrimaryUpdate
#ELSE
#FIX(%Secondary,%TreeLevelFile)
#EMBED(%BeforeCallingUpdateOnEdit,'Before Update Procedure on Edit'),%ActiveTemplateInstance,%Secondary,MAP(%ActiveTemplateInstance,%ActiveTemplateinstanceDescription)
#EMBED(%AfterCallingUpdateOnEdit,'After Update Procedure on Edit'),%ActiveTemplateInstance,%Primary,MAP(%ActiveTemplateInstance,%ActiveTemplateinstanceDescription)
#ELSE
#EMBED(%AfterCallingUpdateOnEdit,'After Update Procedure on Edit'),%ActiveTemplateInstance,%Secondary,MAP(%ActiveTemplateInstance,%ActiveTemplateinstanceDescription)
#EMBED(%BeforeCallingUpdateOnRemove,'Before Update Procedure on Remove'),%ActiveTemplateInstance,%Primary,MAP(%ActiveTemplateInstance,%ActiveTemplateinstanceDescription)
%PrimaryUpdate
#ELSE
#FIX(%Secondary,%TreeLevelFile)
#EMBED(%BeforeCallingUpdateOnRemove,'Before Update Procedure on Remove'),%ActiveTemplateInstance,%Secondary,MAP(%ActiveTemplateInstance,%ActiveTemplateinstanceDescription)
%SecondaryUpdate
#ENDIF
#?IF GlobalResponse = RequestCompleted
#?DO %InstancePrefix:RefreshTree
#?END
#IF(%ValueConstruct = 1)
#EMBED(%AfterCallingUpdateOnRemove,'After Update Procedure on Remove'),%ActiveTemplateInstance,%Primary,MAP(%ActiveTemplateInstance,%ActiveTemplateinstanceDescription)
#ELSE
#EMBED(%AfterCallingUpdateOnRemove,'After Update Procedure on Remove'),%ActiveTemplateInstance,%Secondary,MAP(%ActiveTemplateInstance,%ActiveTemplateinstanceDescription)
#CONTROL(RelTreeUpdateButtons,'Update buttons for a Relation Tree'),DESCRIPTION('Update buttons for a Relation Tree for ' & %Primary),REQ(RelationTree),HLP('~TPLControlBrowseUpdateButtons')